import time

from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait

from po.pingce_page import Pingce
from po.pull_setting import Pullsetting
from po.seacher import Seacher
from tools.base_page import BasePage


class IndexPage(BasePage):
    # 搜索
    seach = ('id', 'search_edit_text')
    source_logcator = ('id', 'comm_item_course_title')
    seach_res = ('id', 'page_recycler_empty_text')  # 没有更多内容了~

    def comprehensive_seach(self, seacher_data):
        self.find(self.seach).click()
        WebDriverWait(self.driver, 10).until(expected_conditions.visibility_of_element_located(self.seach))
        self.find(self.seach).send_keys(seacher_data)
        a = self.driver.available_ime_engines
        self.driver.activate_ime_engine('com.iflytek.inputmethod/.FlyIME')
        # self.driver.activate_ime_engine('com.sohu.inputmethod.sogou.xiaomi/.SogouIME')
        time.sleep(5)
        self.try_and_except()
        self.driver.activate_ime_engine('io.appium.settings/.UnicodeIME')
        try:
            if self.clickable_or_not(self.seach_res):
                self.back_activity(1)
                time.sleep(1)
                return True

        except:
            if self.is_element(self.source_logcator):
                return Seacher(self.driver)
            self.back_activity(1)
            time.sleep(1)
            return True

        # self.clickable_or_not(self.source_logcator)
        # self.elements(self.source_logcator)[0].click()
        # self.back_activity(1)

        #
        # return Seacher(self.driver)

    def goto_push(self):
        push_logcator = ('id', 'notify_content')
        if self.is_element(push_logcator) == True:
            self.find(push_logcator).click()
            return Pullsetting(self.driver)
        else:
            print('此账号没有消息通知')
            return True

    # 去评测:职业域
    def go_to_evaluating(self):
        zhiyeyu = ('text', '职业性格')
        self.find_element(zhiyeyu).click()
        return Pingce(self.driver)
